package com.zjs.jsp.axd.web;


import com.zjs.jsp.axd.service.JspApiService;
import com.zjs.jsp.domain.axd.AxdOrderRootData;
import com.zjs.jsp.domain.config.WebHelpService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

/**
 * 查询订单
 *
 * @author 李文
 * @create 2017-10-11 13:42
 **/
@RestController
public class QueryOrderApiController
{
    private static final Logger LOGGER_FACTORY = LoggerFactory.getLogger(QueryOrderApiController.class);

    @Value("${orderkey:fales}")
    private String orderkey;

    @Autowired
    JspApiService jspApiService;

    @Value("${clientFlag}")
    private String clientFlag;

    @Value("${secret}")
    private String secret;


    @ApiOperation(value = "查询订单", notes = "查询订单，批量查询")
    @ApiImplicitParam(name = "root", value = "数据", required = true, dataType = "AxdOrderRootData", paramType = "body")
    @PostMapping("/order/query/list/{sig}")
    public String orderinQuiry(@PathVariable String sig, @RequestBody AxdOrderRootData root, HttpServletRequest request) {

        String uuid = UUID.randomUUID().toString().replace("-", "");
        LOGGER_FACTORY.info("{} 接受的数据是 {}    {}", uuid, root, WebHelpService.getParameterMap(request));
        String y = WebHelpService.sidData(orderkey, secret, sig, uuid, root);
        if (y == null) {
            try {
                y = jspApiService.orderinQuiry(uuid, root);
            } catch (Exception e) {
                LOGGER_FACTORY.error("{}  调用jspApi服务异常 ", uuid, e);
                return WebHelpService.getString(50007, "接受数据无法格式化");
            }
        }
        LOGGER_FACTORY.info(uuid + " 响应的数据是 {}", y);
        return y;
    }


}
